package top.xunfong.configuration;

import top.xunfong.constant.ProviderEnum;
import top.xunfong.knowledge.service.OSSService;
import top.xunfong.knowledge.service.impl.AliYunOSSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
@Configuration
public class OSSConfiguration {

    @Value("${oss.provider:aliyun}")
    private String provider;


    @Bean
    public OSSService ossService() {
        ProviderEnum providerEnum = ProviderEnum.getByCode(provider);
        switch (providerEnum) {
            case ALI_YUN:
                return new AliYunOSSService(ossServiceExecutorService());
            case TENCENT:
                break;
            default:
                log.info("未知的对象存储服务商");
                break;
        }
        return null;
    }

    /**
     * 创建一个线程池
     *
     * @return
     */
    public ExecutorService ossServiceExecutorService() {
        return Executors.newFixedThreadPool(10);
    }

}
